<template>
  <section class="todoapp">
    <TodoHeader @add="addList"></TodoHeader>
    <!-- This section should be hidden by default and shown when there are todos -->
    <TodoMain :list="list" @del="delList"></TodoMain>
    <!-- This footer should be hidden by default and shown when there are todos -->
    <TodoFooter></TodoFooter>
  </section>
</template>

<script>
import TodoHeader from "@/components/TodoHeader.vue";
import TodoMain from "@/components/TodoMin.vue";
import TodoFooter from "@/components/TodoFooter.vue";
export default {
  components: {
    TodoHeader,
    TodoMain,
    TodoFooter,
  },
  data() {
    return {
      list: [
        { id: 12, name: "吃饭", isDone: false },
        { id: 14, name: "揍吱吱", isDone: true },
        { id: 23, name: "洗澡", isDone: true },
        { id: 34, name: "睡觉", isDone: false },
        { id: 35, name: "游戏", isDone: false },
      ],
    };
  },
  methods: {
    // 删除
    delList(id) {
      console.log(id);
      this.list = this.list.filter((item) => item.id !== id);
    },
    // 添加
    addList(todoname) {
      this.list.unshift({
        id: Date.now(),
        name: todoname,
        isDone: false,
      });
    },
  },
};
</script>

<style></style>
